﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OurSite.Business.Helper;
using OurSite.Business.Picture;
using OurSite.Business.Repositories;
using OurSite.Business.Video;

namespace OurSite.Business.Event
{
    public enum Family {Ryan = 1, Harden = 2}

    public class Event : BaseClass
    {
        protected IPictureRepository pictureRepository = new PictureRepository();
        protected IList<Picture.Picture> pictures;
        protected IVideoRepository videoRepository = new VideoRepository();
        protected IList<Video.Video> videos;
        protected IList<Event> subEvents = new List<Event>();
        protected IList<Category.Category> eventCategories = new List<Category.Category>();
        protected Picture.Picture listingPicture;

        public virtual Guid ParentId { get; set; }
        public virtual int EventCode { get; set; }
        public virtual string ShortDescription { get; set; }
        public virtual string LongDescription { get; set; }
        public virtual string AlternateURL { get; set; }
        public virtual string Region { get; set; }
        public virtual string Country { get; set; }
        public virtual string State { get; set; }
        public virtual string City { get; set; }
        public virtual string Location { get; set; }
        public virtual DateTime StartDate { get; set; }
        public virtual DateTime EndDate { get; set; }
        public virtual int Order { get; set; }
        public virtual int Year { get; set; }
        public virtual int Month { get; set; }
        public virtual int Day { get; set; }
        public virtual Picture.Picture ListingPicture
        {
            get
            {
                if (pictures != null && pictures.Count != 0)
                    listingPicture = pictures.FirstOrDefault(i => i.IsListing);

                if (listingPicture == null)
                    listingPicture = pictureRepository.GetBlankPicture();

                return listingPicture;
            }
            set { listingPicture = value; }
        }
        public virtual IList<Picture.Picture> Pictures 
        { 
            get 
            {
                if (pictures == null)
                    return new List<Picture.Picture>();
                
                return pictures;
            }
            set { pictures = value; }
        }
        public virtual IList<Video.Video> Videos
        {
            get
            {
                if (videos == null)
                    return new List<Video.Video>();

                return videos;
            }
            set { videos = value; }
        }
        
        public virtual IList<Event> SubEvents
        {
            get
            {
                if (subEvents == null)
                    return new List<Event>();

                return subEvents;

            }
            set { subEvents = value; }
        }
        public virtual IList<Category.Category> EventCategories
        {
            get; set;
            //get
            //{
            //    if (eventCategories == null)
            //        return new List<Category.Category>();

            //    return eventCategories;

            //}
            //set { eventCategories = value; }
        }
        public virtual string FacebookId { get; set; }
        public virtual int Family { get; set; }
        public static string BuildImageBasePath(Event evt)
        {
            StringBuilder sbPath = new StringBuilder();
            sbPath.Append("Pictures/");
            sbPath.Append(evt.StartDate.Year + "/");
            sbPath.Append(evt.StartDate.ToString("MMMM") + "/");
            sbPath.Append(HelperUtilities.ReplaceSpecialCharacters(evt.Name) + "/");

            return sbPath.ToString();
        }
        public virtual string DateRange
        {
            get
            {
                StringBuilder returnstring = new StringBuilder();
                returnstring.Append(StartDate.ToShortDateString());
                if (EndDate > DateTime.MinValue)
                    returnstring.Append(" to " + EndDate.ToShortDateString());

                return returnstring.ToString();
            }
        }
        public virtual string FullLocation
        {
            get
            {
                StringBuilder returnstring = new StringBuilder();

                if (!string.IsNullOrEmpty(City))
                    returnstring.Append(City);

                if (!string.IsNullOrEmpty(State))
                    returnstring.Append(", " + State);

                if (!string.IsNullOrEmpty(Country))
                    returnstring.Append(", " + Country);

                return returnstring.ToString();
            }


        }
    }


}
